home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / kernel / testport / testport.c < prev   
C/C++ Source or Header  |  1995-03-25  |  3KB  |  125 lines

  1.  
  2. struct large_s {
  3.     double r, g, b;
  4.     char a[8];
  5.     double c, m, y;
  6. };
  7.  
  8. struct small_s {
  9.     int i;
  10. };
  11.  
  12. #include <dynace.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #define PRINT_LARGE_S(s)            \
  17. printf(#s                    \
  18. " = {\n"                    \
  19. "    r: %lf, g: %lf, b:%lf;\n"            \
  20. "    a: \"%s\";\n"                \
  21. "    c: %lf, m: %lf, y: %lf;\n};\n",        \
  22. s.r, s.g, s.b, s.a, s.c, s.m, s.y)
  23.  
  24. #define PRINT_SMALL_S(s)            \
  25. printf(#s                    \
  26. " = {\n"                    \
  27. "    i: %i;\n};\n",                \
  28. s.i)
  29.  
  30. static int
  31. Method_1(char *self, int i, double d, struct large_s S, char c,
  32.      struct small_s s)
  33. {
  34.     printf("\n--------- in Method_1()\n");
  35.     printf("self: %s\n", self);
  36.     printf("d: %lf\n", d);
  37.     PRINT_LARGE_S(S);
  38.     printf("c: %c\n", c);
  39.     PRINT_SMALL_S(s);
  40.     return 1;
  41. }
  42.  
  43. static double
  44. Method_2(char *self, struct large_s S)
  45. {
  46.     printf("\n--------- in Method_2()\n");
  47.     printf("self: %s\n", self);
  48.     PRINT_LARGE_S(S);
  49.     return S.r;
  50. }
  51.  
  52. static struct large_s
  53. Method_3(char *self, struct large_s S)
  54. {
  55.     printf("\n--------- in Method_3()\n");
  56.     printf("self: %s\n", self);
  57.     S.g /= 2.0;
  58.     S.b /= 3.0;
  59.     strcpy(S.a, "There!");
  60.     PRINT_LARGE_S(S);
  61.     return S;
  62. }
  63.  
  64. static struct small_s
  65. Method_4(char *self, struct small_s s)
  66. {
  67.     printf("\n--------- in Method_4()\n");
  68.     printf("self: %s\n", self);
  69.     s.i *= 3;
  70.     PRINT_SMALL_S(s);
  71.     return s;
  72. }
  73.  
  74. ofun
  75. _FindMethod(object o1, object o2)
  76. {
  77.     static int invocation = 0;
  78.  
  79.     switch(++invocation) {
  80.     case 1: return (ofun)Method_1;
  81.     case 2: return (ofun)Method_2;
  82.     case 3: return (ofun)Method_3;
  83.     case 4: return (ofun)Method_4;
  84.     default: return NULL;
  85.     }
  86. }
  87.  
  88. static object obj = (object)"Some object pointer";
  89.  
  90. int
  91. main()
  92. {
  93.     struct large_s S;
  94.     struct small_s s;
  95.     int i_result;
  96.     double d_result;
  97.     struct large_s S_result;
  98.     struct small_s s_result;
  99.  
  100.     printf("\n--------- in main()\n");
  101.     S.r = 33333.33333; S.g = S.r * 2.0; S.b = S.r * 3.0;
  102.     strcpy(S.a, "Hello!");
  103.     S.c = 13579.013579; S.m = 24680.246802; S.y = 0.0;
  104.     PRINT_LARGE_S(S);
  105.  
  106.     s.i = 13;
  107.     PRINT_SMALL_S(s);
  108.  
  109.     i_result = gFunction_1(obj, 1, 2.0, S, '!', s);
  110.     printf("i_result: %i\n", i_result);
  111.  
  112.     d_result = gFunction_2(obj, S);
  113.     printf("d_result: %lf\n", d_result);
  114.  
  115.     S_result = gFunction_3(obj, S);
  116.     PRINT_LARGE_S(S_result);
  117.     PRINT_LARGE_S(S);
  118.  
  119.     s_result = gFunction_4(obj, s);
  120.     PRINT_SMALL_S(s_result);
  121.     PRINT_SMALL_S(s);
  122. }
  123.  
  124. /* ---EOF--- testport.c */
  125.